package com.reagent.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @Description: 自定义返回类
 * @ClassNmae: Result
 * @Author: HeYue
 * @DateTime: 2020-11-14 17:40
 **/
@Data
public class Result {

    @ApiModelProperty(value = "状态码")
    private Integer status;

    @ApiModelProperty(value = "消息")
    private String message;

    @ApiModelProperty(value = "是否成功")
    private Boolean success;

    @ApiModelProperty(value = "数据")
    private Object data;

    /**
     * 构造方法私有化,里面的方法都是静态方法
     * 达到保护属性的作用
     */
    private Result() {
    }


    /*成功*/
    public static Result success() {
        Result result = new Result();
        result.setSuccess(true);
        result.setStatus(ResultCode.SUCCESS.getStatus());
        result.setMessage(ResultCode.SUCCESS.getMessage());
        return result;
    }

    /*失败*/
    public static Result error() {
        Result result = new Result();
        result.setSuccess(false);
        result.setStatus(ResultCode.ERROR.getStatus());
        result.setMessage(ResultCode.ERROR.getMessage());
        return result;
    }

    /**
     * 自定义返回成功与否
     *
     * @param success
     * @return
     */
    public Result success(Boolean success) {
        this.setSuccess(success);
        return this;
    }

    public Result message(String message) {
        this.setMessage(message);
        return this;
    }

    public Result code(Integer status) {
        this.setStatus(status);
        return this;
    }

    public Result data(Object data) {
        this.setData(data);
        return this;
    }

}
